# coding=utf-8
# author=haishan09@gmail.com
from django import forms
from chart.models import Chart
from custom.widgets import JsonifyConfigWidget
from common.configs import configmanager


class ChartForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        super(ChartForm, self).__init__(*args, **kwargs)
        instance = kwargs.get('instance')
        if instance:
            self.fields['default_config'].widget = JsonifyConfigWidget(configmanager.get_config('chart', instance.name)())

    class Meta:
        model = Chart 
        fields = '__all__'

